home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The PC-SIG Library 10
/
The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso
/
PC_SIGCD
/
05
/
6
/
DISK0564.ZIP
/
SOURCE.ARC
/
RO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1986-04-10
|
2KB
|
69 lines
/* this program write-protects one or more files */
/* for MSDOS Version 2 or higher */
/* usage: ro file1 file2 ... */
/* file name can be ambiguous */
/* for Aztec C86 v. 3.20e */
/* by Jon Dart, 29-Mar-1986 */
#define Version "1.1 (10-Apr-86)"
#include "stdio.h"
#include "fixpath.h"
#include "sgtty.h"
#include "ctype.h"
#include "truth.h"
#include "ascii.h"
#define PATHSIZE 128
#define ROBIT 0x0001
#define DIRBIT 0x0010
extern char *malloc();
char *sp,*lip,*fn,*fn2;
int attrib;
ro(fn)
char *fn;
{
if ((attrib & (DIRBIT+ROBIT))==0) {
/* not a directory and not already r/o */
if (chmod(fn,(attrib | ROBIT) & 0xFF) == -1)
printf("%s: can't change attribute.\n",fn2);
}
}
main(argc,argv)
int argc; char *argv[];
{
int n;
sp = malloc(PATHSIZE);
lip = malloc(PATHSIZE);
fn = malloc(PATHSIZE);
fn2 = malloc(PATHSIZE);
if (argc<=1) {
fprintf(stderr,"ro -- makes files read-only (protects them)\n");
fprintf(stderr,"%s%s\n\n","by Jon Dart ... Version ",Version);
fprintf(stderr,"Usage:\n ro file1 file2 ....\n");
fprintf(stderr," (file names can be ambiguous)\n");
exit(1);
}
for (n=1;n<argc;n++) {
fixpath(argv[n],sp,lip);
if (getfirst(sp,0x21,fn,&attrib)) {
strcpy(fn2,lip);
strcat(fn2,fn);
ro(fn2);
while (getnext(fn,&attrib)) {
strcpy(fn2,lip);
strcat(fn2,fn);
ro(fn2);
}
}
else {
fprintf(stderr,"%s%s\n","Error - can't find: ",argv[n]);
}
}
}